import { defineStore } from 'pinia';

interface ObjectList {
    [key: string]: string[];
}

export const usePermissStore = defineStore('permiss', {
    state: () => {
        const defaultList: ObjectList = {
            admin: [
                '0',
                '11',
                '12',
                '13',
                '14',
                '15',
                '25',
            ],
            teacher: [
                '0',
                '21',
                '22',
                '23',
                '24',
                '25'],
        };
        const username = localStorage.getItem('vuems_name');

        // 新增：读取角色信息
        const role = localStorage.getItem('vuems_role');

        console.log(role);
        return {
            key: (role == 'admin' ? defaultList.admin : defaultList.teacher) as string[],
            defaultList,
        };
        // return {
        //     key: (username == 'admin' ? defaultList.admin : defaultList.teacher) as string[],
        //     defaultList,
        // };
    },
    actions: {
        handleSet(val: string[]) {
            this.key = val;
        },
        updatePermissionsBasedOnRole(role: string) {
            // 新增：根据角色动态更新权限列表
            this.key = this.defaultList[role] || [];
        },
    },
});
